import os

import yaml


class YamlUtils():

    # 读取yaml文件
    def read_yaml(self, file):
        path =os.getcwd() + './Data_Layer/' + str(file)
        with open(path, 'r', encoding='utf-8') as f:
           data =yaml.load(f, Loader=yaml.FullLoader)
           return data

    # w 会覆盖yaml中的内容  a 为追加相关内容
    def write_yaml(self, data, file):
        with open(os.getcwd() + './Data_Layer/' + str(file), mode='a', encoding='utf-8') as f:
            yaml.dump(data=data, stream=f, allow_unicode=True)

    # 清除yaml文件
    def clear_yaml(self, file):
        with open(os.getcwd() + './Data_Layer/' + str(file), mode='w', encoding='utf-8') as f:
            f.truncate()